/*
 * ImmediateCrypt
 * Copyright (C) 2012 Giacomo Drago
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * http://giacomodrago.com/go/immediatecrypt
 * 
 */

package com.giacomodrago.immediatecrypt.gui;

import com.giacomodrago.utils.gui.DesktopUtils;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.*;

@SuppressWarnings("serial")
public class AboutWindow extends JDialog {
   
    private final String programName;
    private final String programVersion;
    private final String programCopyright;
    private final String programWebsite;
    

    public AboutWindow(Frame owner, String programName, String programVersion, String programCopyright,
            String programWebsite) {
        super(owner, true);
        this.programName = programName;
        this.programVersion = programVersion;
        this.programWebsite = programWebsite;
        this.programCopyright = programCopyright;
        initComponents();
        customInitComponents();
    }
    
    private void customInitComponents() {
        getRootPane().setDefaultButton(buttonClose);
        setLocationRelativeTo(getOwner());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelProgramName = new JLabel();
        buttonClose = new JButton();
        labelAuthor = new JLabel();
        labelLicense = new JLabel();
        labelWebsite = new JLabel();
        labelImage = new JLabel();

        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("About");
        setResizable(false);

        labelProgramName.setFont(labelProgramName.getFont().deriveFont(labelProgramName.getFont().getStyle() | Font.BOLD, labelProgramName.getFont().getSize()+5));
        labelProgramName.setHorizontalAlignment(SwingConstants.CENTER);
        labelProgramName.setText("<html>"+programName+" <small>"+programVersion+"</small>");

        buttonClose.setText("Close");
        buttonClose.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                buttonCloseActionPerformed(evt);
            }
        });

        labelAuthor.setHorizontalAlignment(SwingConstants.CENTER);
        labelAuthor.setText(programCopyright);

        labelLicense.setForeground(new Color(153, 153, 153));
        labelLicense.setHorizontalAlignment(SwingConstants.CENTER);
        labelLicense.setText("Released under GPLv3 License");

        labelWebsite.setFont(labelWebsite.getFont());
        labelWebsite.setForeground(Color.blue);
        labelWebsite.setHorizontalAlignment(SwingConstants.CENTER);
        labelWebsite.setText("Visit project website");
        labelWebsite.setCursor(new Cursor(Cursor.HAND_CURSOR));
        labelWebsite.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent evt) {
                labelWebsiteMouseClicked(evt);
            }
        });

        labelImage.setHorizontalAlignment(SwingConstants.CENTER);
        labelImage.setIcon(new ImageIcon(getClass().getResource("/com/giacomodrago/immediatecrypt/gui/icon_128.png"))); 
        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 222, Short.MAX_VALUE)
                .addComponent(buttonClose)
                .addContainerGap())
            .addComponent(labelAuthor, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(labelProgramName, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(labelLicense, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
            .addComponent(labelWebsite, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(labelImage, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelImage)
                .addGap(18, 18, 18)
                .addComponent(labelProgramName)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(labelAuthor)
                .addGap(18, 18, 18)
                .addComponent(labelLicense)
                .addGap(18, 18, 18)
                .addComponent(labelWebsite)
                .addPreferredGap(ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                .addComponent(buttonClose)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonCloseActionPerformed(ActionEvent evt) {//GEN-FIRST:event_buttonCloseActionPerformed
        this.dispose();
    }//GEN-LAST:event_buttonCloseActionPerformed

    private void labelWebsiteMouseClicked(MouseEvent evt) {//GEN-FIRST:event_labelWebsiteMouseClicked
        DesktopUtils.browse(programWebsite);
    }//GEN-LAST:event_labelWebsiteMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JButton buttonClose;
    private JLabel labelAuthor;
    private JLabel labelImage;
    private JLabel labelLicense;
    private JLabel labelProgramName;
    private JLabel labelWebsite;
    // End of variables declaration//GEN-END:variables
}
